/**
 * 微信-发布数量
 */
(function($, window, document, undefined) {
    var comChart;

    var WechatPublish = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons',
            chartOption:{
                'columnDefs': [{
                    "targets": [0],
                    "orderable": false,
                    "data": "post_time",
                    "name": "post_time"
                }, {
                    "targets": [1],
                    "orderable": false,
                    "data": "read_num",
                    "name": "read_num"
                }, {
                    "targets": [2],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [3],
                    "orderable": false,
                    "data": "title",
                    "name": "title"
                }, {
                    "targets": [4],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [5],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [6],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [7],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [8],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }]
            }
        };
        this.options = $.extend({}, this.defaults, opts)
    };

    WechatPublish.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == true) {
                return me;
            }

            me.initAjaxTable();
            me.bindEvents();

            el.attr('data-initialized', 'true');
            return me;
        },

        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;
        },

        initAjaxTable: function() {
            var me = this,
                el = me.el,
                option;

            option = {
                'columnDefs': [{
                    "targets": [0],
                    "orderable": false,
                    "data": "post_time",
                    "name": "post_time"
                }, {
                    "targets": [1],
                    "orderable": false,
                    "data": "read_num",
                    "name": "read_num"
                }, {
                    "targets": [2],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [3],
                    "orderable": false,
                    "data": "title",
                    "name": "title"
                }, {
                    "targets": [4],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [5],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [6],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [7],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }, {
                    "targets": [8],
                    "orderable": false,
                    "data": "author",
                    "name": "author"
                }]
            };


            //init table-managed
            TableAjax.init(option || {});
        }
    };

    $.fn.WechatPublish = function(opts) {
        var me = this,
            el = me.el,
            comWechatPublish;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comWechatPublish = new WechatPublish(this, opts);
        }

        return comWechatPublish.init();
    };

})(jQuery, window, document);
